
	var work={
// 变量
		tel:'',//手机号
// 初始化
		init:function(){
			this.getSms();
			this.sendLayer();
			this.dataTable();
			this.clickEvent();
		},
/*---------------------DOM操作---------------------------------------*/	
//点击事件集合
		clickEvent:function(){
			$(".searchButton").click(function(){
		      work.tel=$("#searchName").val();
		      // alert(work.tel);
		     $("#smsTable").dataTable().api().draw();
		    });
		},
//短信模板下拉	
		getTpl:function(str){
			$(".tpl").empty();
			$(".tpl").append(str);
		},
//点击发送按钮后的弹窗
		sendLayer:function(){
			$(".sub").click(function(){
				layer.msg("正在发送中···");
			});
		},
		//初始化表单
/*---------------------功能性代码---------------------------------------*/
		//短信模板下拉
		getSms:function(){
			$.get("/index.php?m=Service&c=Sms&a=getTpl",function(data){
				var str='<option value="" disabled="disabled" selected>请选择发送模板</option>';
				if(data.length!==0){
					for(x in data){
						str+='<option value="'+data[x].sno+'">'+data[x].title+'</option>';
					}
				}
				work.getTpl(str);
			});
		},
		//关闭本级layer并刷新父级页面
		closeLayer:function(){
			var index = parent.layer.getFrameIndex(window.name);
            setTimeout(function(){
                parent.layer.close(index);
            },1000);
            parent.location.reload();
		},
/*--------------------------初始化----------------------------------*/
		// 表格重绘
		tableDraw:function(){
			$("#smsTable").dataTable().api().draw();
		},
		// 表格初始化
		dataTable:function(tel){
			  var table=$("#smsTable");
		      var t=table.dataTable({
		        "ajax":function(data,callback,setting){
		          var page = table.api().page.info();
		          $.post("/index.php?m=Service&c=Sms&a=search",{pageIndex:page.page+1,pageSize:page.length,tel:work.tel},function(data,status){
		            console.log(data);
		              callback(data); 
		          });
		        },

		        "pageLength":10,
		          "ordering":false,
		          "deferRender": true,
		          "columns":[
		          {"data":"id"},
		          {"data":"id"},
		          {"data":"tel"},
		          {"data":"tpl"},
		          {"data":"time"},
		          {"data":"stat"},
		          ],
		          "columnDefs":[
		          {
		            "targets":0,
		            "data":"id",
		            "render":function(data,type,full,meta){
		              return '<input type="checkbox" value="'+data+'" name="sms_id">';
		            }
		          },
		          {
		            "targets":5,
		            "data":"stat",
		            "render":function(data,type,full,meta){
		              	switch(data){
		              		case "1":
		              			return '<span class="c-success">发送成功</span>';
		              			break;
		              		case "0":
		              			return '<span class="c-red">发送失败</span>';
		              			break;
		              	}
		            }

		          },
		          ],
		        "fnCreatedRow":function(row,data,index){
		          //row 表示当前tr，data表示当前行的元素对象，index表示当前tr索引
		        },
		      "bPaginate": true, //翻页功能
		      // "processing": true,
		      "searching":false,
		      "serverSide": true,//服务器模式
		        });
		},
	};

